﻿Imports System.Data.OleDb

Public Class hotelDetail
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btn_comment_Click(sender As Object, e As EventArgs) Handles btn_comment.Click

        Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("hotelsConnectionString").ConnectionString)
        Dim sql = "INSERT INTO comment (Author, Subject, Message, HotelID) VALUES (@f1, @f2, @f3, @f4)"
        Dim cmd = New OleDbCommand(sql, conn)

        conn.Open()
        cmd.Parameters.AddWithValue("@f1", tb_name.Text)
        cmd.Parameters.AddWithValue("@f2", tb_title.Text)
        cmd.Parameters.AddWithValue("@f3", tb_comment.Text)
        cmd.Parameters.AddWithValue("@f4", Request.Params("ID"))
        cmd.ExecuteNonQuery()
        conn.Close()

        Response.Redirect("hotelDetail.aspx?ID=" & Request.Params("ID"))


    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim hotelId = Request.Params("ID")
        Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("hotelsConnectionString").ConnectionString)
        conn.Open()
        For Each li As ListItem In CheckBoxList1.Items
            If (li.Selected = True) Then
                Dim sql = "INSERT INTO HotelTagJunction (tag_fkid, hotel_fkid) VALUES (@f1, @f2)"
                Dim cmd As New OleDbCommand(sql, conn)
                cmd.Parameters.AddWithValue("@f1", li.Value)
                cmd.Parameters.AddWithValue("@f2", hotelId)
                cmd.ExecuteNonQuery()
            End If
        Next
        conn.Close()

    End Sub
End Class